.PHONY: all clean

ifeq (${P_BASE},)
all:
	@echo "ERROR: the variable [P_BASE] is not set"
else
include ${P_BASE}/global/utils/make/target
include ${P_BASE}/global/utils/make/cmds

all: ${T_BASE}/boot_sect.bin
endif

${T_BASE}/boot_sect.bin: boot_sect.asm ${T_BASE}/boot_s1.bin
	@$(call C_ECHO,MAKE boot_sect.bin)
	${V}$(call C_SETENV,T_BASE,${T_BASE}) $(call C_SETENV,P_BASE,${P_BASE}) \
	$(call C_SH,${P_BASE}/global/utils/make_boot_sect.sh)

${T_BASE}/boot_s1_asm.o: boot_s1_asm.S
	@$(call C_ECHO,CC $@)
	${V}$(call T_CC,$<,$@,${T_CC_FLAG_INC}${P_BASE} ${T_CC_FLAG_OBJ})

${T_BASE}/boot_s1.o: boot_s1.c
	@$(call C_ECHO,CC $@)
	${V}$(call T_CC,$<,$@,${T_CC_FLAG_INC}${P_BASE} ${T_CC_FLAG_OBJ})

${T_BASE}/boot_s1.bin: ${T_BASE}/boot_s1_asm.o ${T_BASE}/boot_s1.o
	@$(call C_ECHO,LD $@)
	${V}$(call T_LD,$^,$@.out,-N -e s1_asm_main -Ttext 0x8000)
	${V}$(call T_OBJCOPY,$@.out,$@,-S -Obinary)
	${V}$(call C_RM,$@.out)

